package com.tele.service.imps;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tele.domain.User;
import com.tele.domain.UserLoginVo;
import com.tele.mapper.LoginMapper;
import com.tele.service.ints.LoginService;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImp extends ServiceImpl<LoginMapper, User> implements LoginService {

    //根据openid查询用户
    @Override
    public User getByOpenid(String openId) {
        QueryWrapper<User> wrapper = new QueryWrapper<User>();
        wrapper.eq("open_id", openId);
        User user = baseMapper.selectOne(wrapper);
        return user;
    }

    //得到用户登录信息
    @Override
    public UserLoginVo getUserLoginVo(Long userId) {
        UserLoginVo userLoginVo = new UserLoginVo();
        User user = this.getById(userId);
        System.out.println(user);
        if (user != null) {
            userLoginVo.setNickName(user.getNickName());
            userLoginVo.setUserId(userId);
            userLoginVo.setPhotoUrl(user.getPhotoUrl());
            userLoginVo.setOpenId(user.getOpenId());
        }
        return userLoginVo;
    }
}
